package com.aruba.attendance.home.view

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Panorama
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontVariation.weight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.aruba.attendance.database.entity.RecordEntity

/**
 * 打卡记录item
 * Created by aruba on 2023/2/16.
 */
@Composable
fun RecordListItem(
    recordEntity: RecordEntity,
    modifier: Modifier = Modifier,
    onIconClick: (() -> Unit)? = null
) {
    Card {
        Row(
            horizontalArrangement = Arrangement.SpaceBetween,
            verticalAlignment = Alignment.CenterVertically,
            modifier = modifier
                .fillMaxWidth()
                .padding(start = 10.dp)
        ) {
            Text(
                text = recordEntity.time,
                style = MaterialTheme.typography.bodyLarge
            )

            if (recordEntity.type == RecordEntity.TYPE_GO_WORK && recordEntity.delayDuration != null) {
                Text(
                    text = "迟到:${recordEntity.delayDuration!! / (1000 * 60)}分钟",
                    style = MaterialTheme.typography.bodyLarge.copy(color = MaterialTheme.colorScheme.error),
                    textAlign = TextAlign.End,
                    modifier = Modifier
                        .padding(end = 15.dp)
                        .weight(1f)
                )
            }

            IconButton(onClick = { onIconClick?.invoke() }) {
                Icon(
                    Icons.Default.Panorama,
                    contentDescription = "showPicture",
                    tint = MaterialTheme.colorScheme.onSurface
                )
            }
        }
    }
}